<?php

namespace apiend\models;

use common\helpers\Url;

/**
 * APP文档帮助模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class HelpSearch extends \common\models\help\Help {

    /**
     * 列表查询
     * @return array
     */
    public function search($limits = 4) {
        return static::find()
        ->active(static::STATUS_ACTIVE)
        ->andWhere(['category_id' => 3])
        ->orderBy([
            'listorder' => SORT_ASC,
            'created_at' => SORT_DESC
        ])
        ->limit($limits)
        ->all();
    }

    public function getLink() {
        return Url::h5('help/view/' . $this->id);
    }

    public function getWeblink() {
        return Url::weblink('help/view/{id}', [
            'id' => $this->id
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'title',
            'cover',
            'link',
            'weblink',
            'publish_time' => 'created_at',
        ];
    }

}
